<template><div><h2 id="调试工具栏和调试器" tabindex="-1"><a class="header-anchor" href="#调试工具栏和调试器"><span>调试工具栏和调试器</span></a></h2>
<p>This extension provides a debugger for Yii 2 applications. When this extension is used, a debugger toolbar will appear at the bottom of every page. The extension also provides a set of standalone pages to display more detailed debug information.</p>
<p>The toolbar displays information about the currently opened page, while the debugger can be used to analyze data you’ve previously collected (i.e., to confirm the values of variables).</p>
<p>Out of the box these tools allow you to:</p>
<ul>
<li>quickly get the framework version, PHP version, response status, current controller and action, performance info and more via toolbar;</li>
<li>browse the application and PHP configuration;</li>
<li>view the request data, request and response headers, session data, and environment variables;</li>
<li>see, search, and filter the logs;</li>
<li>view any profiling results;</li>
<li>view the database queries executed by the page;</li>
<li>view the emails sent by the application.</li>
</ul>
<p>All of this information will be available per request, allowing you to revisit the information for past requests as well.</p>
<h2 id="安装" tabindex="-1"><a class="header-anchor" href="#安装"><span>安装</span></a></h2>
<p>The preferred way to install this extension is through <a href="http://getcomposer.org/download/" target="_blank" rel="noopener noreferrer">composer</a>.</p>
<p>Either run</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line">php composer<span class="token operator">.</span>phar <span class="token keyword">require</span> <span class="token operator">--</span>prefer<span class="token operator">-</span>dist yiisoft<span class="token operator">/</span>yii2<span class="token operator">-</span>debug</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>or add</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string double-quoted-string">"yiisoft/yii2-debug"</span><span class="token punctuation">:</span> <span class="token string double-quoted-string">"~2.0.0"</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>to the require section of your <code v-pre>composer.json</code> file.</p>
<h2 id="配置应用" tabindex="-1"><a class="header-anchor" href="#配置应用"><span>配置应用</span></a></h2>
<p>To enable extension, add these lines to your configuration file to enable the debug module:</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'bootstrap'</span> <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'debug'</span><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token string single-quoted-string">'modules'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token string single-quoted-string">'debug'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'class'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'yii\debug\Module'</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token punctuation">]</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>You will see a debugger toolbar showing at the bottom of every page of your application. You can click on the toolbar to see more detailed debug information.</p>
<p>By default, the debug module only works when browsing the website from localhost. If you want to use it on a remote (staging) server, add the parameter <code v-pre>allowedIPs</code> to the configuration to whitelist your IP:</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'bootstrap'</span> <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'debug'</span><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token string single-quoted-string">'modules'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token string single-quoted-string">'debug'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'class'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'yii\debug\Module'</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'allowedIPs'</span> <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'1.2.3.4'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'127.0.0.1'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'::1'</span><span class="token punctuation">]</span></span>
<span class="line">    <span class="token punctuation">]</span></span>
<span class="line"><span class="token punctuation">]</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>If you are using <code v-pre>enableStrictParsing</code> URL manager option, add the following to your <code v-pre>rules</code>:</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'urlManager'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token string single-quoted-string">'enableStrictParsing'</span> <span class="token operator">=></span> <span class="token constant boolean">true</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token string single-quoted-string">'rules'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token comment">// ...</span></span>
<span class="line">        <span class="token string single-quoted-string">'debug/&lt;controller>/&lt;action>'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'debug/&lt;controller>/&lt;action>'</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><blockquote>
<p>Note: the debugger stores information about each request in the <code v-pre>@runtime/debug</code> directory. If you have problems using the debugger, such as weird error messages when using it, or the toolbar not showing up or not showing any requests, check whether the web server has enough permissions to access this directory and the files located inside.</p>
</blockquote>
<h3 id="日志和分析的额外配置" tabindex="-1"><a class="header-anchor" href="#日志和分析的额外配置"><span>日志和分析的额外配置</span></a></h3>
<p>Logging and profiling are simple but powerful tools that may help you to understand the execution flow of both the framework and the application. These tools are useful for development and production environments alike.</p>
<p>While in a production environment, you should log only significantly important messages manually, as described in <a href="https://github.com/yiisoft/yii2/blob/master/docs/guide/runtime-logging.md" target="_blank" rel="noopener noreferrer">logging guide section</a>. It hurts performance too much to continue to log all messages in production.</p>
<p>In a development environment, the more logging the better, and it’s especially useful to record the execution trace.</p>
<p>In order to see the trace messages that will help you to understand what happens under the hood of the framework, you need to set the trace level in the configuration file:</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">return</span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token comment">// ...</span></span>
<span class="line">    <span class="token string single-quoted-string">'components'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'log'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">            <span class="token string single-quoted-string">'traceLevel'</span> <span class="token operator">=></span> <span class="token constant">YII_DEBUG</span> <span class="token operator">?</span> <span class="token number">3</span> <span class="token punctuation">:</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token comment">// &lt;-- here</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>By default, the trace level is automatically set to <code v-pre>3</code> if Yii is running in debug mode, as determined by the presence of the following line in your <code v-pre>index.php</code> file:</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token function">defined</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'YII_DEBUG'</span><span class="token punctuation">)</span> <span class="token keyword">or</span> <span class="token function">define</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'YII_DEBUG'</span><span class="token punctuation">,</span> <span class="token constant boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><blockquote>
<p>Note: Make sure to disable debug mode in production environments since it may have a significant and adverse performance effect. Further, the debug mode may expose sensitive information to end users.</p>
</blockquote>
<h3 id="配置数据库面板" tabindex="-1"><a class="header-anchor" href="#配置数据库面板"><span>配置数据库面板</span></a></h3>
<p>Database panel default sorting and filtering can be configured like the following:</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$config</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'modules'</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'debug'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token string single-quoted-string">'class'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'yii\debug\Module'</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token string single-quoted-string">'panels'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'db'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">            <span class="token string single-quoted-string">'class'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'yii\debug\panels\DbPanel'</span><span class="token punctuation">,</span></span>
<span class="line">            <span class="token string single-quoted-string">'defaultOrder'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">                <span class="token string single-quoted-string">'seq'</span> <span class="token operator">=></span> <span class="token constant">SORT_ASC</span></span>
<span class="line">            <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">            <span class="token string single-quoted-string">'defaultFilter'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">                <span class="token string single-quoted-string">'type'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'SELECT'</span></span>
<span class="line">            <span class="token punctuation">]</span></span>
<span class="line">        <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="在ide中打开的额外配置" tabindex="-1"><a class="header-anchor" href="#在ide中打开的额外配置"><span>在IDE中打开的额外配置</span></a></h3>
<p>Wouldn’t it be nice to be able to open files directly from the debug trace?</p>
<p>Well, you can! With a few settings you’re ready to go!</p>
<p>You can create a link to open files in your favorite IDE with this configuration:</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">return</span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token string single-quoted-string">'bootstrap'</span> <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'debug'</span><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token string single-quoted-string">'modules'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'debug'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">            <span class="token string single-quoted-string">'class'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'yii\debug\Module'</span><span class="token punctuation">,</span></span>
<span class="line">            <span class="token string single-quoted-string">'traceLine'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'&lt;a href="phpstorm://open?url={file}&amp;line={line}">{file}:{line}&lt;/a>'</span><span class="token punctuation">,</span></span>
<span class="line">            <span class="token comment">// uncomment and adjust the following to add your IP if you are not connecting from localhost.</span></span>
<span class="line">            <span class="token comment">//'allowedIPs' => ['127.0.0.1', '::1'],</span></span>
<span class="line">        <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token comment">// ...</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>You must make some changes to your OS. See these examples:</p>
<ul>
<li>PHPStorm: <a href="https://github.com/aik099/PhpStormProtocol" target="_blank" rel="noopener noreferrer">github.com/aik099/PhpStormProtocol</a></li>
<li>Sublime Text 3 on Windows or Linux: <a href="https://packagecontrol.io/packages/subl%20protocol" target="_blank" rel="noopener noreferrer">packagecontrol.io/packages/subl%20...</a></li>
<li>Sublime Text 3 on Mac: <a href="https://github.com/inopinatus/sublime_url" target="_blank" rel="noopener noreferrer">github.com/inopinatus/sublime_url</a></li>
</ul>
<h4 id="windows" tabindex="-1"><a class="header-anchor" href="#windows"><span>Windows</span></a></h4>
<h5 id="_1-create-a-wscript-file-open-phpstorm-js" tabindex="-1"><a class="header-anchor" href="#_1-create-a-wscript-file-open-phpstorm-js"><span>1) Create a WScript file open_phpstorm.js:</span></a></h5>
<p>Create a file <code v-pre>C:\Program Files (x86)\JetBrains\open_phpstorm.js</code> (example for PhpStorm) with the following content:</p>
<div class="language-javascript line-numbers-mode" data-highlighter="prismjs" data-ext="js" data-title="js"><pre v-pre class="language-javascript"><code><span class="line"><span class="token keyword">var</span> settings <span class="token operator">=</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token comment">// Set to 'true' (without quotes) if run on Windows 64bit. Set to 'false' (without quotes) otherwise.</span></span>
<span class="line">    <span class="token literal-property property">x64</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span></span>
<span class="line"></span>
<span class="line">    <span class="token comment">// Set to folder name, where PhpStorm was installed to (e.g. 'PhpStorm')</span></span>
<span class="line">    <span class="token literal-property property">folder_name</span><span class="token operator">:</span> <span class="token string">'PhpStorm 2016.2.1'</span><span class="token punctuation">,</span></span>
<span class="line"></span>
<span class="line">    <span class="token comment">// Set to window title (only text after dash sign), that you see, when switching to running PhpStorm instance</span></span>
<span class="line">    <span class="token literal-property property">window_title</span><span class="token operator">:</span> <span class="token string">'PhpStorm 2016.2.1'</span><span class="token punctuation">,</span></span>
<span class="line"></span>
<span class="line">    <span class="token comment">// In case your file is mapped via a network share and paths do not match.</span></span>
<span class="line">    <span class="token comment">// eg. /var/www will can replaced with Y:/</span></span>
<span class="line">    <span class="token literal-property property">projects_basepath</span><span class="token operator">:</span> <span class="token string">''</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token literal-property property">projects_path_alias</span><span class="token operator">:</span> <span class="token string">''</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// don't change anything below this line, unless you know what you're doing</span></span>
<span class="line"><span class="token keyword">var</span>    url <span class="token operator">=</span> WScript<span class="token punctuation">.</span><span class="token function">Arguments</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">    match <span class="token operator">=</span> <span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">^ide:\/\/(?:.+)file:\/\/(.+)&amp;line=(\d+)$</span><span class="token regex-delimiter">/</span></span><span class="token punctuation">.</span><span class="token function">exec</span><span class="token punctuation">(</span>url<span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">    project <span class="token operator">=</span> <span class="token string">''</span><span class="token punctuation">,</span></span>
<span class="line">    editor <span class="token operator">=</span> <span class="token string">'"C:\\'</span> <span class="token operator">+</span> <span class="token punctuation">(</span>settings<span class="token punctuation">.</span>x64 <span class="token operator">?</span> <span class="token string">'Program Files'</span> <span class="token operator">:</span> <span class="token string">'Program Files (x86)'</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token string">'\\JetBrains\\'</span> <span class="token operator">+</span> settings<span class="token punctuation">.</span>folder_name <span class="token operator">+</span> <span class="token string">'\\bin\\PhpStorm.exe"'</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">if</span> <span class="token punctuation">(</span>match<span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line"></span>
<span class="line">    <span class="token keyword">var</span>    shell <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ActiveXObject</span><span class="token punctuation">(</span><span class="token string">'WScript.Shell'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        file_system <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">ActiveXObject</span><span class="token punctuation">(</span><span class="token string">'Scripting.FileSystemObject'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        file <span class="token operator">=</span> <span class="token function">decodeURIComponent</span><span class="token punctuation">(</span>match<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">\+</span><span class="token regex-delimiter">/</span><span class="token regex-flags">g</span></span><span class="token punctuation">,</span> <span class="token string">' '</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        search_path <span class="token operator">=</span> file<span class="token punctuation">.</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">\/</span><span class="token regex-delimiter">/</span><span class="token regex-flags">g</span></span><span class="token punctuation">,</span> <span class="token string">'\\'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token keyword">if</span> <span class="token punctuation">(</span>settings<span class="token punctuation">.</span>projects_basepath <span class="token operator">!=</span> <span class="token string">''</span> <span class="token operator">&amp;&amp;</span> settings<span class="token punctuation">.</span>projects_path_alias <span class="token operator">!=</span> <span class="token string">''</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">        file <span class="token operator">=</span> file<span class="token punctuation">.</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">RegExp</span><span class="token punctuation">(</span><span class="token string">'^'</span> <span class="token operator">+</span> settings<span class="token punctuation">.</span>projects_basepath<span class="token punctuation">)</span><span class="token punctuation">,</span> settings<span class="token punctuation">.</span>projects_path_alias<span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">    <span class="token keyword">while</span> <span class="token punctuation">(</span>search_path<span class="token punctuation">.</span><span class="token function">lastIndexOf</span><span class="token punctuation">(</span><span class="token string">'\\'</span><span class="token punctuation">)</span> <span class="token operator">!=</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">        search_path <span class="token operator">=</span> search_path<span class="token punctuation">.</span><span class="token function">substring</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> search_path<span class="token punctuation">.</span><span class="token function">lastIndexOf</span><span class="token punctuation">(</span><span class="token string">'\\'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token keyword">if</span><span class="token punctuation">(</span>file_system<span class="token punctuation">.</span><span class="token function">FileExists</span><span class="token punctuation">(</span>search_path<span class="token operator">+</span><span class="token string">'\\.idea\\.name'</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">            project <span class="token operator">=</span> search_path<span class="token punctuation">;</span></span>
<span class="line">            <span class="token keyword">break</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token punctuation">}</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">    <span class="token keyword">if</span> <span class="token punctuation">(</span>project <span class="token operator">!=</span> <span class="token string">''</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">        editor <span class="token operator">+=</span> <span class="token string">' "%project%"'</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">    editor <span class="token operator">+=</span> <span class="token string">' --line %line% "%file%"'</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token keyword">var</span> command <span class="token operator">=</span> editor<span class="token punctuation">.</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">%line%</span><span class="token regex-delimiter">/</span><span class="token regex-flags">g</span></span><span class="token punctuation">,</span> match<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">)</span></span>
<span class="line">                        <span class="token punctuation">.</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">%file%</span><span class="token regex-delimiter">/</span><span class="token regex-flags">g</span></span><span class="token punctuation">,</span> file<span class="token punctuation">)</span></span>
<span class="line">                        <span class="token punctuation">.</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">%project%</span><span class="token regex-delimiter">/</span><span class="token regex-flags">g</span></span><span class="token punctuation">,</span> project<span class="token punctuation">)</span></span>
<span class="line">                        <span class="token punctuation">.</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token regex"><span class="token regex-delimiter">/</span><span class="token regex-source language-regex">\/</span><span class="token regex-delimiter">/</span><span class="token regex-flags">g</span></span><span class="token punctuation">,</span> <span class="token string">'\\'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    shell<span class="token punctuation">.</span><span class="token function">Exec</span><span class="token punctuation">(</span>command<span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    shell<span class="token punctuation">.</span><span class="token function">AppActivate</span><span class="token punctuation">(</span>settings<span class="token punctuation">.</span>window_title<span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h5 id="_2-create-a-registry-file-and-execute-this-file" tabindex="-1"><a class="header-anchor" href="#_2-create-a-registry-file-and-execute-this-file"><span>2) Create a registry file and execute this file</span></a></h5>
<p>Create a registry file <code v-pre>C:\Program Files (x86)\JetBrains\open_phpstorm.reg</code> (example for PhpStorm) with the following content and make sure the paths are correct:</p>
<div class="language-reg line-numbers-mode" data-highlighter="prismjs" data-ext="reg" data-title="reg"><pre v-pre class="language-reg"><code><span class="line">Windows Registry Editor Version 5.00</span>
<span class="line"></span>
<span class="line">[HKEY_CLASSES_ROOT\ide]</span>
<span class="line">@=&quot;\&quot;URL:ide Protocol\&quot;&quot;</span>
<span class="line">&quot;URL Protocol&quot;=&quot;&quot;</span>
<span class="line"></span>
<span class="line">[HKEY_CLASSES_ROOT\ide\shell\open\command]</span>
<span class="line">@=&quot;wscript \&quot;C:\\Program Files (x86)\\JetBrains\\open_phpstorm.js\&quot; %1&quot;</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>Now you are able to use the ide:// protocol in your browser.</p>
<p>When you click such a link, the IDE will automatically open the file and move the cursor to the corresponding line.</p>
<h5 id="disable-links" tabindex="-1"><a class="header-anchor" href="#disable-links"><span>Disable links</span></a></h5>
<p>IDE links for traces are created by default. You have to set the property <code v-pre>yii\debug\Module::traceLink</code> to false to render a textual line only.</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token php language-php"><span class="token delimiter important">&lt;?php</span></span>
<span class="line"></span>
<span class="line"><span class="token operator">...</span></span>
<span class="line"><span class="token string single-quoted-string">'modules'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token string single-quoted-string">'debug'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'class'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'yii\debug\Module'</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'traceLink'</span> <span class="token operator">=></span> <span class="token constant boolean">false</span></span>
<span class="line">    <span class="token punctuation">]</span></span>
<span class="line"><span class="token punctuation">]</span></span>
<span class="line"></span>
<span class="line"><span class="token operator">...</span></span>
<span class="line"></span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="virtualized-or-dockerized" tabindex="-1"><a class="header-anchor" href="#virtualized-or-dockerized"><span>Virtualized or dockerized</span></a></h3>
<p>If your application is run under a virtualized or dockerized environment, it is often the case that the application’s base path is different inside of the virtual machine or container than on your host machine. For the links work in those situations, you can configure <code v-pre>tracePathMappings</code> like this (change the path to your app):</p>
<div class="language-text-html-php line-numbers-mode" data-highlighter="prismjs" data-ext="text-html-php" data-title="text-html-php"><pre v-pre class="language-text-html-php"><code><span class="line">'tracePathMappings' =&gt; [</span>
<span class="line">    '/app' =&gt; '/path/to/your/app',</span>
<span class="line">],</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>Or you can create a callback for <code v-pre>traceLine</code> for even more control:</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'traceLine'</span> <span class="token operator">=></span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token variable">$options</span><span class="token punctuation">,</span> <span class="token variable">$panel</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token variable">$filePath</span> <span class="token operator">=</span> <span class="token variable">$options</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'file'</span><span class="token punctuation">]</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token class-name static-context">StringHelper</span><span class="token operator">::</span><span class="token function">startsWith</span><span class="token punctuation">(</span><span class="token variable">$filePath</span><span class="token punctuation">,</span> <span class="token class-name static-context">Yii</span><span class="token operator">::</span><span class="token variable">$app</span><span class="token operator">-></span><span class="token property">basePath</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token variable">$filePath</span> <span class="token operator">=</span> <span class="token string single-quoted-string">'~/path/to/your/app'</span> <span class="token operator">.</span> <span class="token function">substr</span><span class="token punctuation">(</span><span class="token variable">$filePath</span><span class="token punctuation">,</span> <span class="token function">strlen</span><span class="token punctuation">(</span><span class="token class-name static-context">Yii</span><span class="token operator">::</span><span class="token variable">$app</span><span class="token operator">-></span><span class="token property">basePath</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line">    <span class="token keyword">return</span> <span class="token function">strtr</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'&lt;a href="ide://open?url=file://{file}&amp;line={line}">{text}&lt;/a>'</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'{file}'</span> <span class="token operator">=></span> <span class="token variable">$filePath</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="切换用户" tabindex="-1"><a class="header-anchor" href="#切换用户"><span>切换用户</span></a></h3>
<p>You can use log in as any user and reset to back to your primary user. In order to enable the feature you need to configure access permissions in the <code v-pre>UserPanel</code> config. By default access is denied to everyone.</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">return</span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token string single-quoted-string">'bootstrap'</span> <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'debug'</span><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token string single-quoted-string">'modules'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'debug'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">            <span class="token string single-quoted-string">'class'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'yii\debug\Module'</span><span class="token punctuation">,</span></span>
<span class="line">            <span class="token string single-quoted-string">'panels'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">                <span class="token string single-quoted-string">'user'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">                    <span class="token string single-quoted-string">'class'</span><span class="token operator">=></span><span class="token string single-quoted-string">'yii\debug\panels\UserPanel'</span><span class="token punctuation">,</span></span>
<span class="line">                    <span class="token string single-quoted-string">'ruleUserSwitch'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">                        <span class="token string single-quoted-string">'allow'</span> <span class="token operator">=></span> <span class="token constant boolean">true</span><span class="token punctuation">,</span></span>
<span class="line">                        <span class="token string single-quoted-string">'roles'</span> <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'manager'</span><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">                    <span class="token punctuation">]</span></span>
<span class="line">                <span class="token punctuation">]</span></span>
<span class="line">            <span class="token punctuation">]</span></span>
<span class="line">        <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token comment">// ...</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>For details see <a href="http://www.yiiframework.com/doc-2.0/guide-security-authorization.html" target="_blank" rel="noopener noreferrer">Guide Authorization</a>.</p>
<h3 id="skipping-urls-from-being-displayed-in-toolbar" tabindex="-1"><a class="header-anchor" href="#skipping-urls-from-being-displayed-in-toolbar"><span>Skipping URLs from being displayed in toolbar</span></a></h3>
<p>In some cases, such as AJAX-polling, toolbar is getting spammed quickly and becomes unusable. There is a way to ignore these URLs for such cases:</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">return</span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token string single-quoted-string">'bootstrap'</span> <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'debug'</span><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token string single-quoted-string">'modules'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'debug'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">            <span class="token string single-quoted-string">'class'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'yii\debug\Module'</span><span class="token punctuation">,</span></span>
<span class="line">            <span class="token string single-quoted-string">'skipAjaxRequestUrl'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">                <span class="token string single-quoted-string">'notification/status'</span></span>
<span class="line">            <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token comment">// ...</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token operator">...</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="自定义面板" tabindex="-1"><a class="header-anchor" href="#自定义面板"><span>自定义面板</span></a></h2>
<p>Both the toolbar and debugger are highly configurable and customizable. To do so, you can create your own panels that collect and display the specific data you want. Below we’ll describe the process of creating a simple custom panel that:</p>
<ul>
<li>collects the views rendered during a request;</li>
<li>shows the number of views rendered in the toolbar;</li>
<li>allows you to check the view names in the debugger.</li>
</ul>
<p>The assumption is that you’re using the basic project template.</p>
<p>First we need to implement the <code v-pre>Panel</code> class in <code v-pre>panels/ViewsPanel.php</code>:</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token php language-php"><span class="token delimiter important">&lt;?php</span></span>
<span class="line"><span class="token keyword">namespace</span> <span class="token package">app<span class="token punctuation">\</span>panels</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">yii<span class="token punctuation">\</span>base<span class="token punctuation">\</span>Event</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">yii<span class="token punctuation">\</span>base<span class="token punctuation">\</span>View</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">yii<span class="token punctuation">\</span>base<span class="token punctuation">\</span>ViewEvent</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">yii<span class="token punctuation">\</span>debug<span class="token punctuation">\</span>Panel</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">class</span> <span class="token class-name-definition class-name">ViewsPanel</span> <span class="token keyword">extends</span> <span class="token class-name">Panel</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token keyword">private</span> <span class="token variable">$_viewFiles</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">init</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword static-context">parent</span><span class="token operator">::</span><span class="token function">init</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token class-name static-context">Event</span><span class="token operator">::</span><span class="token function">on</span><span class="token punctuation">(</span><span class="token class-name static-context">View</span><span class="token operator">::</span><span class="token function">className</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token class-name static-context">View</span><span class="token operator">::</span><span class="token constant">EVENT_BEFORE_RENDER</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token class-name type-declaration">ViewEvent</span> <span class="token variable">$event</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">            <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">_viewFiles</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token variable">$event</span><span class="token operator">-></span><span class="token property">sender</span><span class="token operator">-></span><span class="token function">getViewFile</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">    <span class="token doc-comment comment">/**</span>
<span class="line">     * <span class="token punctuation">{</span><span class="token keyword">@inheritdoc</span><span class="token punctuation">}</span></span>
<span class="line">     */</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">getName</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">return</span> <span class="token string single-quoted-string">'Views'</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">    <span class="token doc-comment comment">/**</span>
<span class="line">     * <span class="token punctuation">{</span><span class="token keyword">@inheritdoc</span><span class="token punctuation">}</span></span>
<span class="line">     */</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">getSummary</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token variable">$url</span> <span class="token operator">=</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token function">getUrl</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token variable">$count</span> <span class="token operator">=</span> <span class="token function">count</span><span class="token punctuation">(</span><span class="token variable">$this</span><span class="token operator">-></span><span class="token property">data</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token keyword">return</span> <span class="token string double-quoted-string">"&lt;div class=\"yii-debug-toolbar__block\">&lt;a href=\"<span class="token interpolation"><span class="token variable">$url</span></span>\">Views &lt;span class=\"yii-debug-toolbar__label yii-debug-toolbar__label_info\"><span class="token interpolation"><span class="token variable">$count</span></span>&lt;/span>&lt;/a>&lt;/div>"</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">    <span class="token doc-comment comment">/**</span>
<span class="line">     * <span class="token punctuation">{</span><span class="token keyword">@inheritdoc</span><span class="token punctuation">}</span></span>
<span class="line">     */</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">getDetail</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">return</span> <span class="token string single-quoted-string">'&lt;ol>&lt;li>'</span> <span class="token operator">.</span> <span class="token function">implode</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'&lt;/li>&lt;li>'</span><span class="token punctuation">,</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">data</span><span class="token punctuation">)</span> <span class="token operator">.</span> <span class="token string single-quoted-string">'&lt;/li>&lt;/ol>'</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"></span>
<span class="line">    <span class="token doc-comment comment">/**</span>
<span class="line">     * <span class="token punctuation">{</span><span class="token keyword">@inheritdoc</span><span class="token punctuation">}</span></span>
<span class="line">     */</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">save</span><span class="token punctuation">(</span><span class="token punctuation">)</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">return</span> <span class="token variable">$this</span><span class="token operator">-></span><span class="token property">_viewFiles</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>The workflow for the code above is:</p>
<ol>
<li><code v-pre>init</code> is executed before any controller action is run. This method is the best place to attach handlers that will collect data during the controller action’s execution.</li>
<li><code v-pre>save</code> is called after controller action is executed. The data returned by this method will be stored in a data file. If nothing is returned by this method, the panel won’t be rendered.</li>
<li>The data from the data file is loaded into <code v-pre>$this-&gt;data</code>. For the toolbar, this will always represent the latest data. For the debugger, this property may be set to be read from any previous data file as well.</li>
<li>The toolbar takes its contents from <code v-pre>getSummary</code>. There, we’re showing the number of view files rendered. The debugger uses <code v-pre>getDetail</code> for the same purpose.</li>
</ol>
<p>Now it’s time to tell the debugger to use the new panel. In <code v-pre>config/web.php</code>, the debug configuration is modified to:</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token constant">YII_ENV_DEV</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token comment">// configuration adjustments for 'dev' environment</span></span>
<span class="line">    <span class="token variable">$config</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'bootstrap'</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string single-quoted-string">'debug'</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token variable">$config</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'modules'</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'debug'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'class'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'yii\debug\Module'</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'panels'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">            <span class="token string single-quoted-string">'views'</span> <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'class'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'app\panels\ViewsPanel'</span><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token comment">// ...</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>That’s it. Now we have another useful panel without writing much code.</p>
<h3 id="advanced-options" tabindex="-1"><a class="header-anchor" href="#advanced-options"><span>Advanced options</span></a></h3>
<h4 id="allow-click-events-in-your-toolbar-summary-block" tabindex="-1"><a class="header-anchor" href="#allow-click-events-in-your-toolbar-summary-block"><span>Allow ‘click’ events in your toolbar summary block</span></a></h4>
<p>By default an inline preview is shown when clicking on the summary on the toolbar. To override this behavior add the <code v-pre>yii-debug-toolbar__block_ignore_click</code> class to your root <code v-pre>&lt;div&gt;</code> in <code v-pre>getSummary()</code>.</p>
<h4 id="events" tabindex="-1"><a class="header-anchor" href="#events"><span>Events</span></a></h4>
<p>If you need client side programmatic access to the toolbar, for example to bind JavaScript events, you can listen to the <code v-pre>yii.debug.toolbar_attached</code> event on the document. For example:</p>
<div class="language-javascript line-numbers-mode" data-highlighter="prismjs" data-ext="js" data-title="js"><pre v-pre class="language-javascript"><code><span class="line">document<span class="token punctuation">.</span><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">'yii.debug.toolbar_attached'</span><span class="token punctuation">,</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">event</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">    <span class="token keyword">var</span> toolbar <span class="token operator">=</span> event<span class="token punctuation">.</span>target<span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><blockquote>
<p>💖喜欢本文档的，欢迎点赞、收藏、留言或转发，谢谢支持！<br>
作者邮箱：zhuzixian520@126.com，github地址：<a href="https://github.com/zhuzixian520" target="_blank" rel="noopener noreferrer">github.com/zhuzixian520</a></p>
</blockquote>
</div></template>


